<?php

require_once 'class/Jssdk.php';

class menuStub {
    
    //static用在函数里面，声明一次变量后，如果再次调用这个函数将会在初始值延续,和global有点类似，但不同的是作用域。static只能作用于此函数。 
    
    static function https_request($url,$data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        
        //测试变量是否已配置，若已存在、非空或非0，则返回false
        if(!empty($data)){
            curl_setopt($curl, CURLOPT_PORT, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        
        return $output;
    }
    
    static function getUserInfo($object,$infoType){
        $OpenID = $object->FromUserName;
        $Access_Token = JSSDK::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$Access_Token&openid=$OpenID&lang=zh_CN";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    
        $output = curl_exec($curl);
        curl_close($curl);
    
        $jsonInfo = json_decode($output,true);
        $user_info = $jsonInfo[$infoType];
        return $user_info;
    }
    
}